package com.jeasonzhao.commons.json;

import com.jeasonzhao.commons.parser.lex.LexToken;

public class JSONException extends Exception
{
    private static final long serialVersionUID = 1L;
    public JSONException(LexToken tk,String message)
    {
        super(
            (null == tk ? "" : "ERROR: Line at " + (tk.getBeginRowIndex() + 1) + ", Column at "
             + (tk.getBeginColumn() + 1) + ",") +
            message);
    }

    public JSONException(String message)
    {
        super(message);
    }

    public JSONException(Throwable ex)
    {
        super(ex);
    }

    public JSONException(JSONNode node,String message)
    {
        super((null == node ? "" : node.toString()) +
              (null == node || null == node.getToken(0) ? "" :
               "Error: Line at " + (node.getToken(0).getBeginRowIndex() + 1) + ", Column at "
               + (node.getToken(0).getBeginColumn() + 1) + ",") +
              message);
    }

    public JSONException(JSONNode node,JSONNode nodeSub,String message)
    {
        super((null == node ? "" : node.toString()) +
              (null == nodeSub || null == nodeSub.getToken(0) ? "" :
               "Error: Line at " + (nodeSub.getToken(0).getBeginRowIndex() + 1) + ", Column at " +
               (nodeSub.getToken(0).getBeginColumn() + 1) + ",") +
              message);
    }

}
